﻿using JWTMiddre.Middleware;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using static JWTMiddre.Middleware.JwtMiddleware;

namespace JWTMiddre.Controllers
{
    public class HomeController : Controller
    {
        [HttpPost]
        public IActionResult GetToken(string name,string password)
        {
            var user = new AuthenUser()
            {
                name=name,
                sex="未知"
            };
            var authenhandler = new AuthorizationHandler();
            var token = authenhandler.GenerateTokenCredential(fastJSON.JSON.ToJSON(user));
            return Json(new { 
            status="OK",
            token=token
            });
        }

        public IActionResult GetUsername()
        {
            var a = HttpContext.Items["user"];
            return Json(a);
        }
    }
}
